package com.tabjin.rfidsocket.controller.v1.sys;

import com.tabjin.rfidsocket.common.utils.TabJsonResult;
import com.tabjin.rfidsocket.pojo.bo.SysAclModuleBO;
import com.tabjin.rfidsocket.pojo.vo.SysAclModuleVO;
import com.tabjin.rfidsocket.service.sys.SysAclModuleService;
import com.tabjin.rfidsocket.service.sys.SysAclService;
import com.tabjin.rfidsocket.service.sys.SysTreeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author tabjin
 * create at 2020/12/22 16:27
 * @program rfid_socket
 * @description
 */
@RestController
@RequestMapping(value = "/sys/aclModule")
@Slf4j
public class SysAclModuleController {

    private final SysAclModuleService sysAclModuleService;

    private final SysAclService sysAclService;

    private final SysTreeService sysTreeService;

    public SysAclModuleController(SysAclModuleService sysAclModuleService, SysAclService sysAclService, SysTreeService sysTreeService) {
        this.sysAclModuleService = sysAclModuleService;
        this.sysAclService = sysAclService;
        this.sysTreeService = sysTreeService;
    }

    // 页面
    @RequestMapping(value = "/acl.page")
    public ModelAndView page() {
        return new ModelAndView("AclModule");// 需要新的页面aclModule
    }

    /**
     * 新增权限模块
     *
     * @param sysAclModuleBO 权限模块BO类
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public TabJsonResult add(@RequestBody SysAclModuleBO sysAclModuleBO) {
        SysAclModuleVO vo = sysAclModuleService.add(sysAclModuleBO);
        return TabJsonResult.ok(vo);
    }

    /**
     * 更新权限模块
     *
     * @param sysAclModuleBO 权限模块BO类
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public TabJsonResult update(@RequestBody SysAclModuleBO sysAclModuleBO) {
        sysAclModuleService.update(sysAclModuleBO);
        return TabJsonResult.ok();
    }

    @RequestMapping(value = "/tree", method = RequestMethod.GET)
    @ResponseBody
    public TabJsonResult tree() {
        return TabJsonResult.ok(sysTreeService.aclModuleTree());
    }

    /**
     * 删除权限模块
     *
     * @param aclModuleId
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public TabJsonResult delete(@RequestParam(value = "id") Integer aclModuleId) {
        sysAclModuleService.delete(aclModuleId);
        return TabJsonResult.ok();
    }
}
